﻿using CatUtils.LocalUtils.UserView;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.Enhance.Encrypt;
using CatUtils.Utils.Enhance.Translate.BaiduTranslate;
using CatUtils.Utils.SpecialUtils.Html;
using CatUtils.Utils.SpecialUtils.PicBed.Sina;
using CatUtils.Utils.SpecialUtils.PicBed.Sougou;
using CatUtils.Utils.SpecialUtils.View;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace CatUtils
{
    public partial class MainView : Form
    {
        /// <summary>
        /// 主窗口
        /// </summary>
        public MainView()
        {
            InitializeComponent();
            InitView();
        }

        private void InitView()
        {
            Groupboxhelper.InitAll(groupBox1, comboBox1, new List<string> { "111", "2222", "333" });
            FloderHelper.InitFloder();
            comboBox1.Items.AddRange(RepUserView.ComboxList.ToArray());

            //   new ViewInfoMemory().InitComboboxSaveInfo(comboBox1, "Maincombobox");
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(".\\");
        }

        private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            new RepUserView().SelectChanged(groupBox1, comboBox1.Text);

            new ViewInfoMemory().SaveComboBoxInfo("Maincombobox", comboBox1.Text);
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            string Content = FileHelper.ReadAllText(".\\text.txt");
            Console.WriteLine(HtmlHelper.ClearHtml(Content));
        }

        /// <summary>
        /// 分析 url 字符串中的参数信息  使用方法：NameValueCollection["keyName"]
        /// </summary>
        /// <param name="url">输入的 URL</param>
        /// <param name="baseUrl">输出 URL 的基础部分</param>
        /// <param name="nvc">输出分析后得到的 (参数名,参数值) 的集合</param>
        public static NameValueCollection ParseUrl(string url)
        {
            NameValueCollection nvc = new NameValueCollection();
            int questionMarkIndex = url.IndexOf('?');
            if (url == null || questionMarkIndex == -1
                || questionMarkIndex == url.Length - 1)
            {
                return nvc;
            }

            string ps = url.Substring(questionMarkIndex + 1);
            // 开始分析参数对
            Regex re = new Regex(@"(^|&)?(\w+)=([^&]+)(&|$)?", RegexOptions.Compiled);
            MatchCollection mc = re.Matches(ps);
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Result("$2").ToLower());
                Console.WriteLine(m.Result("$3"));
                nvc.Add(m.Result("$2").ToLower(), m.Result("$3"));
            }
            Console.WriteLine(nvc["icce"]);
            if (nvc["icce"] == null) Console.WriteLine("1251");
            return nvc;
        }

        private void button1_Click(object sender, EventArgs e)

        {
            string fileinfo = ".\\info.txt";
            File.Encrypt(fileinfo);
            Console.WriteLine(1212);
            return;

            string Shtml = WebHelper.HttpPcGet("https://game.watch.impress.co.jp/docs/news/1308071.html");
            string Content = HtmlHelper.GetFirstHtml(Shtml, "//div[@id='main']/article");

            BaiduTranslateUtils.InitClient("20160416000018891", "ZfUl91mZjRG6VmaK7pqU");

            BaiduTranslateUtils.HtmlTranslate(Content,
           "auto", "zh", TextHelper.GetRandom(111111111, 999999999));
            return;
            Console.WriteLine(WebHelper.HttpPost("https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records", "")); ;
            return;
            Console.WriteLine(HtmlHelper.ClearHtml("<p></p><br></br><a></a>" + FileHelper.ReadAllText(FileHelper.SelectFile()),
                 HtmlHelper.DelScriptSetting, HtmlHelper.DelStyleSetting, false, HtmlHelper.DelIframeSetting,
 HtmlHelper.DelInvalidImgSetting, HtmlHelper.DelEmptyLableSetting, false, HtmlHelper.WriteAttributesSetting)); ;
            //HtmlHelper.RemoveInvalidImg(FileHelper.ReadAllText(FileHelper.SelectFile()), "//img", new List<string>(), true);
            return;
            Assembly assebly = Assembly.LoadFrom(Application.ExecutablePath);

            Module module = assebly.ManifestModule;
            Type[] types = module.GetTypes();

            Type tpForm = typeof(Form);

            foreach (Type type in types)
            {
                if (type.IsSubclassOf(tpForm))
                {
                    MessageBox.Show(type.FullName);
                }
            }
            return;
            // FileHelper.FileMove();
            Console.WriteLine(FileNameHelper.CreateFileNameWithChildFloder(FileHelper.SelectFile(), "catga"));
            return;
            while (true)
            {
                Console.WriteLine(FileNameHelper.CreateTempFileName());
            };
            //   Console.WriteLine(SougouPicBed.ImgLink("https://www.mymypic.net/data/attachment/forum/202007/11/182406dszddfp27tul6s6z.jpg")); ;
            return;
            //   new SinaLoginForm("https://weibo.com").Show();
            SinaImgUploadTool.InitSecurity();
            PicBedHelper.CheckSinaLogin();
            SinaImgUploadTool.UploadFile(FileHelper.SelectFile());
            // FileHelper.SelectFile();

            //Console.WriteLine();
            return;
            Uri host = new Uri("http://baidu.com");
            Console.WriteLine(host.Host);
            //ParseUrl("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_7_dg&wd=(%5E%7C%26)%3F(%5Cw%2B)%3D(%5B%5E%26%5D%2B)(%26%7C%24)%3F&oq=selenium%25E5%2590%2591%25E4%25B8%258B%25E6%25BB%259A%25E5%258A%25A8&rsv_pq=bb536f7500014880&rsv_t=a241ghl1FNZWWUOrKbatlXstmq%2FBjmeJzas0GJVBTMMPzGNROmqxK1LwTZXkFXE6eUb3&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=2&rsv_n=2&rsv_sug1=1&rsv_sug7=100&rsv_sug2=0&rsv_btype=t&inputT=613&rsv_sug4=705");
            return;
            Console.WriteLine(new Random().NextDouble());
            double cst = 10;
            Console.WriteLine(cst.ToString("0.0"));
            //MessageHelper.DialogYesNoCancle("提示内容", "确定", "否", "取消", 3, DialogResult.OK, "窗口标题");
            return;
            try
            {
                Convert.ToInt16("ccc");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //Console.WriteLine(PrintLog.GetChinemsLog(ex, ErrorTypeName.WebError, true));
            }
            return;
            string FilePath = ".\\text.txt";

            ConfigurationEncrypt.SaveCofiguration("我是123ABb", FilePath, true, true);
            Console.WriteLine(ConfigurationEncrypt.GetCofiguration(FilePath, true, true));
            // BaiduOcrhelper.ReadIDCardFile(FileHelper.SelectFile());
            return;
            Console.WriteLine(
            WebHelper.GetImgInfo("https://sinaimg.inn-studio.com/mw1024/007iocwWly1g3cioh2gfaj30lc0f340g.jpg"));
            return;
            string ImgLink = "http://s8.postimg.org/lv7nx98et/img117.png";
            Console.WriteLine(WebHelper.GetImgInfo(ImgLink));
            if (WebHelper.CheckImgExits(ImgLink, new List<WebHelper.BlockImgInfo> {
                new WebHelper.BlockImgInfo{  FileSize=8844, ImgHeight=480, ImgWidth=360},
                  new WebHelper.BlockImgInfo{  FileSize=8271, ImgHeight=360, ImgWidth=480},
                  new WebHelper.BlockImgInfo{  FileSize=7092, ImgHeight=360, ImgWidth=360}
            })) { Console.WriteLine("图片存在"); }
            else Console.WriteLine("图片不存在");
        }
    }
}